<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>学生信息管理</title>
<link rel="stylesheet" type="text/css"
	href="http://localhost:8080/songtao//resources/jquery/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="http://localhost:8080/songtao//resources/jquery/themes/icon.css">
<script type="text/javascript"
	src="http://localhost:8080/songtao//resources/jquery/jquery.min.js"></script>
<script type="text/javascript"
	src="http://localhost:8080/songtao//resources/jquery/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="http://localhost:8080/songtao//resources/jquery/locale/easyui-lang-zh_CN.js"></script>

<script type="text/javascript">
function newUser(){
    $('#dlg').dialog('open').dialog('setTitle','新学生');
    $('#fm').form('clear');

};


function saveUser(){
    $('#fm').form('submit',{
        url: 'http://localhost:8080/songtao/insert.shtml',
        onSubmit: function(){
            return $(this).form('validate');
        },
        success: function(result){
            var result = eval('1');
            if (result.errorMsg){
                $.messager.show({
                    title: 'Error',
                    msg: result.errorMsg
                });
            } else {
                $('#dlg').dialog('close');        // close the dialog
                $('#dg').datagrid('reload');    // reload the user data
            }
        }
    });
};





function destroyUser(){
    var row = $('#dg').datagrid('getSelected');
    if (row){
        $.messager.confirm('Confirm','确定删除?',function(r){
            if (r){
                $.post('http://localhost:8080/songtao/delete.shtml',{id:row.id},function(result){
                    if (result = eval('1')){
                        $('#dg').datagrid('reload');    // reload the user data
                    } else {
                        $.messager.show({    // show error message
                            title: 'Error',
                            msg: result.errorMsg
                        });
                    }
                },'json');
            }
        });
    }
}

function editUser(){
	var row = $('#dg').datagrid('getSelected');
	if (row){
	    $('#dlg1').dialog('open').dialog('setTitle','修改');
	    $('#fm1').form('load',row);  
	    url = 'http://localhost:8080/songtao/update.shtml?id='+row.id;
	    
	}
};


function updateUser(){
    $('#fm1').form('submit',{
        url: url,
        onSubmit: function(){
            return $(this).form('validate');
        },
        success: function(result){
            var result = eval('1');
            if (result.errorMsg){
                $.messager.show({
                    title: 'Error',
                    msg: result.errorMsg
                });
            } else {
                $('#dlg1').dialog('close');        // close the dialog
                $('#dg').datagrid('reload');    // reload the user data
            }
        }
    });
}


function logout(){
	 $.messager.confirm('Confirm','确定退出?',function(r){

});
</script>

</head>
<body>

<div>
<div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
        closed="true" buttons="#dlg-buttons">
    <div class="ftitle">学生信息</div>
    
   <form id="fm" method="post">
        <div class="fitem">
            <label>名字:</label>
            <input name="name" class="easyui-validatebox" required="true">
        </div>
        <div class="fitem">
            <label>学科:</label>
            <input name="project" class="easyui-validatebox" required="true">
        </div>
        <div class="fitem">
            <label>班级:</label>
            <input name="classId" class="easyui-validatebox" required="true">
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser()">保存</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>
</div>


<div id="dlg1" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
        closed="true" buttons="#dlg-buttons">
    <div class="ftitle">学生信息</div>
    
   <form id="fm1" method="post">
        <div class="fitem">
            <label>名字:</label>
            <input name="name" class="easyui-validatebox" required="true">
        </div>
        
        <div class="fitem">
            <label>密码:</label>
            <input name="password" class="easyui-validatebox" required="true">
        </div>
        <div class="fitem">
            <label>学科:</label>
            <input name="project" class="easyui-validatebox" required="true">
        </div>
        <div class="fitem">
            <label>班级:</label>
            <input name="classId" class="easyui-validatebox" required="true">
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="updateUser()">提交</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>



<table id="dg" title="学生管理" class="easyui-datagrid"
		"
        url="http://localhost:8080/songtao/all1.shtml"
		toolbar="#toolbar" rownumbers="true" fitColumns="true"
		singleSelect="true">
		<thead>
			<tr>
				<th data-options="field:'id'" width="10">id</th>
				<th data-options="field:'name'" width="30">name</th>
<!-- 				<th data-options="field:'createTime'" width="50">createTime</th> -->
				<th data-options="field:'email'" width="50">Email</th>
<!-- 				<th data-options="field:'date'" width="50">Date</th> -->
				<th data-options="field:'image'" width="20">image</th>
				<th data-options="field:'password'" width="50">password</th>
				<th data-options="field:'projectName'" width="20">projectName</th>
				<th data-options="field:'classId'" width="10">classId</th>
			</tr>
		</thead>
	</table>
<div id="toolbar">
		<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"
			onclick="newUser()">增加学生</a> 
			
			
		<a href="#"
			class="easyui-linkbutton" iconCls="icon-edit" plain="true"
			onclick="editUser()">修改学生</a> 
			
		<a href="#"
			class="easyui-linkbutton" iconCls="icon-remove" plain="true"
			onclick="destroyUser()">删除学生</a>
	
			<a href="http://localhost:8080/songtao/logout.shtml"
			class="easyui-linkbutton" iconCls="icon-lock" plain="true"
			onclick="logout()">登出</a>
	
	</div>


<script type="text/javascript">
function newUser(){
    $('#dlg').dialog('open').dialog('setTitle','新学生');
    $('#fm').form('clear');

};







function editUser(){
	var row = $('#dg').datagrid('getSelected');
	if (row){
	    $('#dlg1').dialog('open').dialog('setTitle','修改');
	    $('#fm1').form('load',row);  
	    url = 'http://localhost:8080/songtao/update.shtml?id='+row.id;
	    
	}
}


function destroyUser(){
    var row = $('#dg').datagrid('getSelected');
    if (row){
        $.messager.confirm('Confirm','确定删除?',function(r){
            if (r){
                $.post('http://localhost:8080/songtao/delete.shtml',{id:row.id},function(result){
                    if (result = eval('1')){
                        $('#dg').datagrid('reload');    // reload the user data
                    } else {
                        $.messager.show({    // show error message
                            title: 'Error',
                            msg: result.errorMsg
                        });
                    }
                },'json');
            }
        });
    }
}






function saveUser(){
    $('#fm').form('submit',{
        url: 'http://localhost:8080/songtao/insert.shtml',
        onSubmit: function(){
            return $(this).form('validate');
        },
        success: function(result){
            var result = eval('1');
            if (result.errorMsg){
                $.messager.show({
                    title: 'Error',
                    msg: result.errorMsg
                });
            } else {
                $('#dlg').dialog('close');        // close the dialog
                $('#dg').datagrid('reload');    // reload the user data
            }
        }
    });
}




function updateUser(){
    $('#fm1').form('submit',{
        url: url,
        onSubmit: function(){
            return $(this).form('validate');
        },
        success: function(result){
            var result = eval('1');
            if (result.errorMsg){
                $.messager.show({
                    title: 'Error',
                    msg: result.errorMsg
                });
            } else {
                $('#dlg1').dialog('close');        // close the dialog
                $('#dg').datagrid('reload');    // reload the user data
            }
        }
    });
}
</script>







</body>
</html>